#///////////////////////////////////////////////////////////////////////////////
##.. module:: readFromDB
#
# Read data from database.
#
# Parameters
# !!!!!!!!!!
# lower *(optional)*:
#   the lower bound on the date-time
# lower *(optional)*:
#   the upper bound on the date-time
#
# Returns
# !!!!!!!
# A data.frame made up of date / time, kilowatts, and volts::
# 
#    $dateTime      $kW     $V   
#
# Usage
# !!!!!
# :: 
#
#   # Read all data collected before 2010-08-21
#   readFromDB(upper='2010-08-21') 
#
#   # Read data between 1800 and 2400 on 2010-02-24
#   readFromDB('2010-02-24 18:00:00', '2010-02-24 18:00:00')
#    
##
#///////////////////////////////////////////////////////////////////////////////
readFromDB<-function(lower=1, upper=1) {
    if (lower==1) lower="0000-01-01 00:00:00"
    if (upper==1) upper="9999-12-31 23:59:59" # Warning: Y10K bug.
    query=sprintf("select * from data where dateTime>datetime('%s') and dateTime<datetime('%s')",
            lower, upper)
    print(paste("...", query))
    data = dbGetQuery(con, query)
    if (length(data$kW) == 0) {
        stop("... Nothing read from the database")
    }
    data$dateTime = as.POSIXlt(data$dateTime)
    print(paste("...", "Read from DB.")) 
    return(data)
}
